package org.teachertools.web.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.teachertools.data.Categorie;
import org.teachertools.services.CategorieService;
import org.teachertools.web.forms.CategorieForm;
import org.teachertools.web.forms.CategorieFormMapping;

public class CategorieViewAction extends CommonAction {

    @Override
    protected ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        CategorieService categorieService = this.getServiceLocator().getCategorieService();
        Long id = Long.parseLong(request.getParameter("id"));
        Categorie categorie = categorieService.get(id);
        CategorieFormMapping.mappingDTOToForm(categorie, (CategorieForm) form);
        ((CategorieForm) form).setIsUpdate(Boolean.TRUE);

        addCategoryList(request);

        return (mapping.findForward(CONTINUE));
    }
}
